﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using TyMES.Model.BaseInformation;
using TyMES.Model;

namespace TyMES.ViewModel.BaseInformation.MaterialVMs
{
    public partial class MaterialListVM : BasePagedListVM<Material_View, MaterialSearcher>
    {
        
        protected override IEnumerable<IGridColumn<Material_View>> InitGridHeader()
        {
            return new List<GridColumn<Material_View>>{
                
                this.MakeGridHeader(x => x.Material_MaterialCode).SetTitle(@Localizer["Page.物料编码"].Value),
                this.MakeGridHeader(x => x.Material_MaterialType).SetTitle(@Localizer["Page.物料类型"].Value),
                this.MakeGridHeader(x => x.Material_MaterialName).SetTitle(@Localizer["Page.物料名称"].Value),
                this.MakeGridHeader(x => x.Material_MaterialVersion).SetTitle(@Localizer["Page.物料版本"].Value),
                this.MakeGridHeader(x => x.Material_MeasureUnitCode).SetTitle(@Localizer["Page.计量单位"].Value),
                this.MakeGridHeader(x => x.Material_Regular).SetTitle(@Localizer["Page.正则校验"].Value),
                this.MakeGridHeader(x => x.Material_ShipRegular).SetTitle(@Localizer["Page.出货条码正则校验"].Value),
                this.MakeGridHeader(x => x.Material_MachineStatus).SetTitle(@Localizer["Page.物料状态"].Value),
                this.MakeGridHeader(x => x.Material_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.Material_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.Material_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.Material_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.Material_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Material_View> GetSearchQuery()
        {
            var query = DC.Set<Material>()
                
                .CheckContain(Searcher.MaterialCode, x=>x.MaterialCode)
                .CheckContain(Searcher.MaterialType, x=>x.MaterialType)
                .CheckContain(Searcher.MaterialName, x=>x.MaterialName)
                .CheckContain(Searcher.MaterialVersion, x=>x.MaterialVersion)
                .CheckContain(Searcher.MeasureUnitCode, x=>x.MeasureUnitCode)
                .CheckContain(Searcher.Regular, x=>x.Regular)
                .CheckContain(Searcher.ShipRegular, x=>x.ShipRegular)
                .CheckEqual(Searcher.MachineStatus, x=>x.MachineStatus)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new Material_View
                {
				    ID = x.ID,
                    
                    Material_MaterialCode = x.MaterialCode,
                    Material_MaterialType = x.MaterialType,
                    Material_MaterialName = x.MaterialName,
                    Material_MaterialVersion = x.MaterialVersion,
                    Material_MeasureUnitCode = x.MeasureUnitCode,
                    Material_Regular = x.Regular,
                    Material_ShipRegular = x.ShipRegular,
                    Material_MachineStatus = x.MachineStatus,
                    Material_CreateTime = x.CreateTime,
                    Material_UpdateTime = x.UpdateTime,
                    Material_CreateBy = x.CreateBy,
                    Material_UpdateBy = x.UpdateBy,
                    Material_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Material_View: Material
    {
        
        public string Material_MaterialCode { get; set; }
        public string Material_MaterialType { get; set; }
        public string Material_MaterialName { get; set; }
        public string Material_MaterialVersion { get; set; }
        public string Material_MeasureUnitCode { get; set; }
        public string Material_Regular { get; set; }
        public string Material_ShipRegular { get; set; }
        public BaseStatusEnum? Material_MachineStatus { get; set; }
        public DateTime? Material_CreateTime { get; set; }
        public DateTime? Material_UpdateTime { get; set; }
        public string Material_CreateBy { get; set; }
        public string Material_UpdateBy { get; set; }
        public bool Material_IsValid { get; set; }

    }

}